import React, {Component} from 'react';
import PropTypes from 'prop-types';
import Comment from './Comment';
export default class CommentList extends Component {
    static propTypes = {
        allComments: PropTypes.array
    }

    constructor() {
        super();
        this.state = {
            allComments: []
        }
    }

    componentWillMount() {
        this._handleTime();
    }

    _handleTime() {
        var comment = this.props.myComments;
        this.setState({allComments: comment})
        console.log(comment)
    }

    handleDeleteComment(x){
        if(this.props.onDeleteComment){
            this.props.onDeleteComment(x);
        }
    }

    render() {

        return (
            <div>
                {this
                    .state
                    .allComments
                    .map((com, i) => {
                        return (<Comment comment={com} key={i} onDeleteComment={this.handleDeleteComment.bind(this)} index={i}/>)
                    })
                }

            </div>
        )
    }
}